
package harlequin;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class AttendancePublic extends GeneralAttendance {

    private Connection connector;
    private String query = "insert into attendancegeneralpublic(fullName, organizationCompany, emailAddress, contactNumber, dateTimeslot"
                      + ") values(?,?,?,?,?)";
    public AttendancePublic(Connection connector) {
        this.connector = connector;
        this.setTitle("Attendance");
        initComponents();
        initializeShowComboList2();
    }

private void initializeShowComboList2(){
try {
  Statement stmt = connector.createStatement();
  ResultSet rs = stmt.executeQuery("Select * from play");
  while(rs.next()){
    cShow.addItem(rs.getString("dateTimeslot"));
  }
  } catch (SQLException ex) {
      Logger.getLogger(AttendanceDLSU.class.getName()).log(Level.SEVERE, null, ex);
  }   
}
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cShow = new javax.swing.JComboBox();
        cAttendance = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tOrganizationCompany = new javax.swing.JTextField();
        tContactNumber = new javax.swing.JTextField();
        tEmailAddress = new javax.swing.JTextField();
        tFullName = new javax.swing.JTextField();
        bSubmit = new javax.swing.JButton();
        bBack = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        cShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cShowActionPerformed(evt);
            }
        });
        getContentPane().add(cShow, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 13, -1, -1));

        cAttendance.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "General Public", "DLSU Student" }));
        cAttendance.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cAttendanceActionPerformed(evt);
            }
        });
        getContentPane().add(cAttendance, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 12, -1, -1));

        jLabel1.setText("Full Name:");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 56, -1, -1));

        jLabel3.setText("Organization/Company:");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 85, -1, -1));

        jLabel4.setText("E-mail Address:");
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 117, -1, -1));

        jLabel5.setText("Contact Number:");
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 149, -1, -1));
        getContentPane().add(tOrganizationCompany, new org.netbeans.lib.awtextra.AbsoluteConstraints(152, 82, 156, -1));
        getContentPane().add(tContactNumber, new org.netbeans.lib.awtextra.AbsoluteConstraints(121, 143, 187, -1));
        getContentPane().add(tEmailAddress, new org.netbeans.lib.awtextra.AbsoluteConstraints(121, 114, 187, -1));
        getContentPane().add(tFullName, new org.netbeans.lib.awtextra.AbsoluteConstraints(121, 53, 187, -1));

        bSubmit.setText("Submit");
        bSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSubmitActionPerformed(evt);
            }
        });
        getContentPane().add(bSubmit, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 250, 296, -1));

        bBack.setText("Back");
        bBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBackActionPerformed(evt);
            }
        });
        getContentPane().add(bBack, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 282, 296, -1));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/HTGBG320320.jpg"))); // NOI18N
        jLabel2.setText("    ");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 320, 320));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void cAttendanceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cAttendanceActionPerformed
     if(cAttendance.getSelectedItem() == "DLSU Student")
   {
       this.dispose();
       new AttendanceDLSU(connector).setVisible(true);
   }
   
}//GEN-LAST:event_cAttendanceActionPerformed

private void bSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSubmitActionPerformed

    try {

            fullName = tFullName.getText();
            organization = tOrganizationCompany.getText();
            emailAddress = tEmailAddress.getText();
            contactNumber = tContactNumber.getText();
            
            if(fullName.isEmpty() && organization.isEmpty() && emailAddress.isEmpty() && contactNumber.isEmpty())
               JOptionPane.showMessageDialog(null, "Please input all empty fields.");
              else if (fullName.isEmpty())
                JOptionPane.showMessageDialog(null, "Please indicate your Full Name");
              else if (organization.isEmpty())
                JOptionPane.showMessageDialog(null, "Please indicate your Organization");
              else if (emailAddress.isEmpty())
                JOptionPane.showMessageDialog(null, "Please indicate your Email Address");
              else if (contactNumber.isEmpty())
                  JOptionPane.showMessageDialog(null, "Please indicate your Contact Number");
              else if (contactNumber.length() < 11 || contactNumber.length() > 11)
                JOptionPane.showMessageDialog(null, "Invalid Number");
              else {

            
            java.sql.PreparedStatement preparedStatement = connector.prepareStatement(query);
            preparedStatement.setString(1, fullName);
            preparedStatement.setString(2, organization);
            preparedStatement.setString(3, emailAddress);
            preparedStatement.setString(4, contactNumber);
            preparedStatement.setString(5, this.tempDate);
            

            preparedStatement.executeUpdate();
            JOptionPane.showMessageDialog(null, "Addition Success!");    
            
            this.dispose();
            tOrganizationCompany.setText("");
            tEmailAddress.setText("");
            tFullName.setText("Last/First/Middle");
            tContactNumber.setText("");
            AttendancePublic attendance = new AttendancePublic(connector);
            attendance.setVisible(true);
              }
        } catch (SQLException ex) {
            Logger.getLogger(AttendanceDLSU.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_bSubmitActionPerformed

private void cShowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cShowActionPerformed
  tempDate = cShow.getSelectedItem().toString();
  System.out.println(tempDate);
}//GEN-LAST:event_cShowActionPerformed

private void bBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBackActionPerformed
  this.dispose();
}//GEN-LAST:event_bBackActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBack;
    private javax.swing.JButton bSubmit;
    private javax.swing.JComboBox cAttendance;
    private javax.swing.JComboBox cShow;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField tContactNumber;
    private javax.swing.JTextField tEmailAddress;
    private javax.swing.JTextField tFullName;
    private javax.swing.JTextField tOrganizationCompany;
    // End of variables declaration//GEN-END:variables
}
